package ui;

import config.TestConfigA;
import entity.DemoA;
import entity.DemoB;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 模拟客户端访问
 */
public class TestClient {

    public static void main(String[] args) {
        /**
         * 此处不再使用xml配置文件初始化IOC容器所以使用
         * AnnotationConfigApplicationContext类来初始化
         * 参数为spring配置类 类似之前的bean.xml
         */
        BeanFactory beanFactory = new AnnotationConfigApplicationContext(TestConfigA.class);

//       BeanFactory beanFactory = new ClassPathXmlApplicationContext("bean.xml");
        /**
         * 用默认的方法名做id取容器中的bean
         */
//        DemoA demoA = beanFactory.getBean("createDemoA", DemoA.class);
        /**
         * 用自定义的的id取容器中的bean
         */
        DemoA demoA = beanFactory.getBean("demoA", DemoA.class);
        /**
         * 用默认的方法名做id取容器中的bean
         */
        DemoB demoB = beanFactory.getBean("createDemoB", DemoB.class);

        System.out.println(demoA.getUsername());
        System.out.println(demoB.getUsername());

    }
}